var Soundex = function(text){
	
	this.doIt = function(text){
		var result = "";
		text = text.toLowerCase();
		result += text[0];
		
		text = text.substr(1);
		text = lettersToDigits(text);
		text = removeConsecutives(text);
		text = deleteAndPadTrailing(text);
		
		result+=text;
		
		return result;
	}
	
	var lettersToDigits = function(text){
		var newText = "";
		for(var i = 0; i<text.length;i++){
			var c = text[i];
			if(c == "a" || c == 'e' || c == "i" || c == "o" || c == "u" || c == "h" || c == "w" || c == "y"){
				newText+="0";
			} else if (c == "b" || c == "f" || c == "p" || c == "v"){
				newText+="1";
			} else if (c == "c" || c == "g" || c == "j" || c == "k" || c == "q" || c == "s" || c == "x" || c == "z"){
				newText+="2";
			} else if (c == "d" || c == "t"){
				newText+="3";
			} else if (c == "l"){
				newText+="4";
			} else if (c == "m" || c == "n"){
				newText+="5";
			} else if (c == "r"){
				newText+="6";
			}
		};
		return newText;
	};
	
	var removeConsecutives = function(text){
		var newText = text;
		for(var i = 0; i<newText.length;i++){
			while(newText.indexOf(newText[i]+newText[i])>=0){
				newText.replace(newText[i]+newText[i],newText[i]);
			}
		}
		return newText;
	};
	
	var deleteAndPadTrailing = function(text){
		var newText = text;
		while(newText.indexOf("0")>=0){
			newText = newText.replace("0","");
		}
		while(newText.length<3){
			newText+="0";
		}
		return newText;
	};
};